package savet.gui.dialogos;

import java.awt.Component;
import javax.swing.JTable;
import savet.entidades.atributos.Legenda;

/**
 *
 * @author Adisson Marinho
 */
public class LegendaCellRenderer extends javax.swing.table.DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        Legenda legenda = (Legenda) value;
        String descricao = legenda.getDescricao();
        StringBuilder builder;

        setValue(descricao);

        if (descricao.length() > 90 ) {
            builder = new StringBuilder();
            builder.append("<html>");
            builder.append(descricao.substring(0, 89));
            
            for (int i = 90; i < descricao.length(); i++) {
                builder.append(descricao.charAt(i));
                if (i % 90 == 0) {
                    builder.append("<br/>");
                }
            }
            
            builder.append("</html>");
        } else {
            builder = new StringBuilder(descricao);
        }

        setToolTipText(builder.toString());
        return c;
//        return this ;
    }


}
